package com.seanLab.util;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * Created by ailly on 17-12-8.
 */
public class TopicPair implements Comparable<TopicPair> {
    private int serial;
    private double weight;

    public TopicPair(int serial, double weight) {
        this.serial = serial;
        this.weight = weight;
    }

    @Override
    public int compareTo(TopicPair topicPair) {
        if (this.weight > topicPair.weight) {
            return 1;
        } else if (this.weight < topicPair.weight) {
            return -1;
        } else {
            return 0;
        }
    }

    public int getSerial() {
        return serial;
    }

    public void setSerial(int serial) {
        this.serial = serial;
    }

    public double getWeight() {
        return weight;
    }

    public void setWeight(double weight) {
        this.weight = weight;
    }

    public static List<Integer> getTopTopics(List<Double> topic) {
        List<Integer> topTopics = new ArrayList<>();
        //do something
        int top;
        if (topic.size() > 10) {
            top = 10;
        } else {
            top = topic.size();
        }

        int count = 0;

        List<TopicPair> topicPairs = new ArrayList<>();
        for (double d : topic) {
            topicPairs.add(new TopicPair(count++, d));
        }
        Collections.sort(topicPairs, Collections.reverseOrder());
        for (int i = 0; i < top; i++) {
            topTopics.add(topicPairs.get(i).getSerial());
        }
        return topTopics;
    }

}
